<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('收支分类列表')" />
    <style>
        :root {
            --primary-color: #4361ee;
            --primary-light: #eef2ff;
            --secondary-color: #3f37c9;
            --success-color: #10b981;
            --danger-color: #ef4444;
            --warning-color: #f59e0b;
            --light-color: #f8f9fa;
            --dark-color: #1f2937;
            --border-color: #e5e7eb;
            --card-bg: #ffffff;
            --body-bg: #f3f4f6;
            --table-hover: rgba(67, 97, 238, 0.05);
            --text-color: #374151;
        }

        body {
            background-color: var(--body-bg);
            color: var(--text-color);
            font-family: 'Inter', 'PingFang SC', 'Microsoft YaHei', sans-serif;
        }

        .container-div {
            max-width: 1400px;
            margin: 20px auto;
            padding: 0 20px;
        }

        .search-collapse {
            background: var(--card-bg);
            border-radius: 12px;
            box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
            padding: 20px;
            margin-bottom: 20px;
        }

        .select-list ul {
            display: flex;
            flex-wrap: wrap;
            gap: 15px;
            margin: 0;
            padding: 0;
            list-style: none;
            align-items: center;
        }

        .select-list li {
            display: flex;
            align-items: center;
        }

        .select-list label {
            margin-right: 8px;
            font-weight: 500;
            color: var(--text-color);
            white-space: nowrap;
            font-size: 14px;
        }

        .select-list input,
        .select-list select {
            border: 1px solid var(--border-color);
            border-radius: 8px;
            height: 38px;
            padding: 0 12px;
            min-width: 180px;
            transition: all 0.2s;
            background-color: var(--light-color);
            font-size: 14px;
        }

        .select-list input:focus,
        .select-list select:focus {
            border-color: var(--primary-color);
            box-shadow: 0 0 0 3px rgba(67, 97, 238, 0.1);
            outline: none;
        }

        .select-list select {
            appearance: none;
            background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e");
            background-repeat: no-repeat;
            background-position: right 10px center;
            background-size: 16px;
        }

        .btn {
            border-radius: 8px;
            font-weight: 500;
            padding: 8px 16px;
            transition: all 0.2s;
            box-shadow: none !important;
            font-size: 14px;
            display: inline-flex;
            align-items: center;
            justify-content: center;
            gap: 6px;
        }

        .btn-primary {
            background-color: var(--primary-color);
            border-color: var(--primary-color);
        }

        .btn-primary:hover {
            background-color: var(--secondary-color);
            border-color: var(--secondary-color);
        }

        .btn-success {
            background-color: var(--success-color);
            border-color: var(--success-color);
        }

        .btn-danger {
            background-color: var(--danger-color);
            border-color: var(--danger-color);
        }

        .btn-warning {
            background-color: var(--warning-color);
            border-color: var(--warning-color);
        }

        .btn-sm {
            padding: 6px 12px;
        }

        #toolbar {
            margin-bottom: 20px;
            display: flex;
            gap: 10px;
            flex-wrap: wrap;
            background: var(--card-bg);
            padding: 15px;
            border-radius: 12px;
            box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
        }

        .select-table {
            background: var(--card-bg);
            border-radius: 12px;
            box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
            padding: 20px;
            overflow: hidden;
        }

        .fixed-table-container {
            border: none !important;
            border-radius: 12px;
        }

        .fixed-table-header {
            background-color: var(--primary-light);
        }

        .fixed-table-header th {
            border: none !important;
            font-weight: 600;
            color: var(--dark-color);
            font-size: 14px;
            padding: 12px 8px;
        }

        .table-striped > tbody > tr:nth-of-type(odd) {
            background-color: rgba(0, 0, 0, 0.01);
        }

        .table-striped > tbody > tr:hover {
            background-color: var(--table-hover) !important;
        }

        .table > tbody > tr > td {
            border-top: 1px solid var(--border-color);
            vertical-align: middle;
            padding: 12px 8px;
            font-size: 14px;
        }

        .btn-xs {
            padding: 4px 8px;
            font-size: 12px;
            border-radius: 6px;
            min-width: 60px;
        }

        .fa {
            font-size: 12px;
        }

        .disabled {
            opacity: 0.6;
            pointer-events: none;
        }

        @media (max-width: 768px) {
            .select-list ul {
                flex-direction: column;
                align-items: flex-start;
                gap: 12px;
            }

            .select-list li {
                width: 100%;
            }

            .select-list input,
            .select-list select {
                width: 100%;
            }

            .select-list li:last-child {
                justify-content: flex-end;
                width: 100%;
                margin-top: 10px;
            }

            #toolbar {
                gap: 8px;
            }

            .btn {
                padding: 6px 12px;
                font-size: 13px;
            }
        }
    </style>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>
                        <li>
                            <label>类别名称：</label>
                            <input type="text" name="categoryName" class="form-control" placeholder="输入类别名称"/>
                        </li>
                        <li>
                            <label>类别类型：</label>
                            <select name="categoryType" class="form-control" th:with="type=${@dict.getType('fin_category_type')}">
                                <option value="">所有类型</option>
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                            </select>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-sm" onclick="$.table.search()">
                                <i class="fa fa-search"></i>搜索
                            </a>
                            <a class="btn btn-outline-secondary btn-sm" onclick="$.form.reset()">
                                <i class="fa fa-refresh"></i>重置
                            </a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="system:category:add">
                <i class="fa fa-plus"></i>添加
            </a>
            <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="system:category:edit">
                <i class="fa fa-edit"></i>修改
            </a>
            <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="system:category:remove">
                <i class="fa fa-trash"></i>删除
            </a>
            <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="system:category:export">
                <i class="fa fa-download"></i>导出
            </a>
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table" class="table table-hover"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer" />
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('system:category:edit')}]];
    var removeFlag = [[${@permission.hasPermi('system:category:remove')}]];
    var categoryTypeDatas = [[${@dict.getType('fin_category_type')}]];
    var prefix = ctx + "system/category";

    $(function() {
        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            modalName: "收支分类",
            search: false,
            showRefresh: true,
            showColumns: true,
            showToggle: true,
            showExport: false,
            clickToSelect: true,
            detailView: false,
            striped: true,
            minimumCountColumns: 2,
            showPaginationSwitch: false,
            pagination: true,
            pageSize: 10,
            pageList: [10, 25, 50, 100],
            sidePagination: "server",
            queryParams: function(params) {
                return {
                    pageSize: params.limit,
                    pageNum: params.offset / params.limit + 1,
                    searchText: params.search,
                    sort: params.sort,
                    order: params.order,
                    categoryName: $("input[name='categoryName']").val(),
                    categoryType: $("select[name='categoryType']").val()
                };
            },
            columns: [{
                checkbox: true
            },
            {
                field: 'categoryId',
                title: '类别ID',
                visible: false
            },
            {
                field: 'userId',
                title: '用户ID',
                sortable: true
            },
            {
                field: 'categoryName',
                title: '类别名称',
                sortable: true
            },
            {
                field: 'categoryType',
                title: '类别类型',
                sortable: true,
                formatter: function(value, row, index) {
                   return $.table.selectDictLabel(categoryTypeDatas, value);
                }
            },
            {
                title: '操作',
                align: 'center',
                formatter: function(value, row, index) {
                    var actions = [];
                    actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.categoryId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                    actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.categoryId + '\')"><i class="fa fa-trash"></i>删除</a>');
                    return actions.join('');
                }
            }]
        };
        $.table.init(options);
    });
</script>
</body>
</html>